// 小仓库：layout组件相关配置仓库
import { defineStore } from 'pinia'
 
const useTagsStore = defineStore('TagsStore', {
    state: () => {
        return {
            visitedViews: [{
                path: '/home',
                component: () => import('@/views/home/index.vue'),
                name: 'Home',
                meta: {
                    title: '首页',
                    hidden: false,
                    icon: 'HomeFilled',
                }
            }] as any, // 记录浏览过的页面
        }
    },
    //异步|逻辑的地方
    actions: {
        // 添加浏览记录
        addVisitedViews(view: any) {
            // 判断是否已经添加过
            if (this.visitedViews.some((v: any) => v.path === view.path)) return;
            this.visitedViews.push(view)
        },
        // 删除浏览记录
        delVisitedViews(view: any, route: any) {
            this.visitedViews.forEach((v: any, i: number) => {
                // 判断是否已经添加过
                if (v.path === view.path) {
                    this.visitedViews.splice(i, 1);
                    return;
                }
            })
        },
    },
    persist: {
        enabled: true, // 开启数据持久化
    }
})
 
export default useTagsStore